const Router = require('koa-router')

const UserRouter = new Router({ prefix: '/users' })

const { register, login, changePassword } = require('../controllers/user.controllers')

const { userValidator, verifyUser, cryptPassword, verifyLogin } = require('../middleware/user.middleware')
const { auth } = require('../middleware/auth.middleware')

UserRouter.get('/', (ctx, next) => {
    ctx.body = 'Hello User1！'
})

// 先验证 userValidator->verifyUser 再交由register处理
UserRouter.post('/register', userValidator, verifyUser, cryptPassword, register)
// 用户登陆
UserRouter.post('/login', userValidator, verifyLogin, login)
// 修改密码
UserRouter.patch('/', auth, cryptPassword, changePassword)

module.exports = UserRouter